package com.cnswhy.cloud.server.system.controller;

import com.cnswhy.cloud.common.core.base.request.PageParams;
import com.cnswhy.cloud.common.core.mybatis.conditions.query.QueryWrap;
import com.cnswhy.cloud.server.system.entity.CommonDictionaryItem;
import com.cnswhy.cloud.server.system.dto.CommonDictionaryItemSaveDTO;
import com.cnswhy.cloud.server.system.dto.CommonDictionaryItemUpdateDTO;
import com.cnswhy.cloud.server.system.dto.CommonDictionaryItemPageDTO;
import com.cnswhy.cloud.server.system.service.CommonDictionaryItemService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.cnswhy.cloud.common.core.base.controller.SuperController;
import com.cnswhy.cloud.common.core.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
//import com.github.zuihou.security.annotation.PreAuth;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 字典项
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-13
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/commonDictionaryItem")
@Api(value = "CommonDictionaryItem", tags = "字典项")
//@PreAuth(replace = "commonDictionaryItem:")
public class CommonDictionaryItemController extends SuperController<CommonDictionaryItemService, Long, CommonDictionaryItem, CommonDictionaryItemPageDTO, CommonDictionaryItemSaveDTO, CommonDictionaryItemUpdateDTO> {

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<CommonDictionaryItem> commonDictionaryItemList = list.stream().map((map) -> {
            CommonDictionaryItem commonDictionaryItem = CommonDictionaryItem.builder().build();
            return commonDictionaryItem;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(commonDictionaryItemList));
    }

    /*@Override
    public QueryWrap<CommonDictionaryItem> handlerWrapper(CommonDictionaryItem model, PageParams<CommonDictionaryItem> params) {
        QueryWrap<CommonDictionaryItem> wrapper = super.handlerWrapper(model, params);
        wrapper.lambda().ignore(CommonDictionaryItem::setDictionaryType)
                .eq(CommonDictionaryItem::getDictionaryType, model.getDictionaryType());
        return wrapper;
    }*/
}
